const httpUtil = require('_utils/httpUtil');
import { envConfig } from '../config/index';

class SspUserService {
  login(code, nickName, avatarUrl, jumpCode) {
    const req = {
      code: code,
      nickName: nickName,
      avatarUrl: avatarUrl,
      jumpCode: jumpCode,
    };

    return httpUtil
      .request({
        url: `${envConfig.API_URL}/session/login-mini`,
        method: 'POST',
        data: req,
      })
      .then((response) => {
        response.data = {
          token: 'token',
          userInfo: response.data,
          expireTime: Date.now() + 24 * 60 * 60 * 1000,
        };
        return response;
      })
      .catch((err) => {
        console.log(err);
        return httpUtil.request({
          url: `${envConfig.XY_API_URL}/session/login-mini`,
          method: 'POST',
          data: req,
        });
      });
  }
}

const instance = new SspUserService();

module.exports = instance;
